<template>
  <el-form :model="formData" :rules="rules" ref="formData" label-width="100px" size="small">
    <el-form-item label="账号" prop="loginName">
      <el-input v-model="formData.loginName" disabled></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input type="password" v-model="formData.password" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        @click="submitForm('formData')"
        :disabled="loading"
        :icon="loading?'el-icon-loading':'el-icon-circle-plus-outline'"
      >提交</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { resetPwd } from "@/api/system";
export default {
  data() {
    return {
      formData: {
        loginName: this.$store.getters.loginName,
        userId: this.$store.getters.userId,
        password: "",
      },
      loading:false,
      rules: {
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 20, message: '密码 6 到 20 位数', trigger: 'blur' }
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          resetPwd(this.formData).then((res) => {
            this.loading = false;
            if (res.data.code === this.ERR_OK) {
              this.$message.success(res.data.msg);
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-form {
  padding: 20px 15px;
  width: 350px;
}
</style>